package cn.edu.scau.cmi.zhangjinchuan.hibernate.dao;

import org.hibernate.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.edu.scau.cmi.zhangjinchuan.hibernate.domain.Student;

public class StudentDAO extends BaseHibernateDAO{
	
	private static final Logger log = LoggerFactory.getLogger(StudentDAO.class);
	
	public void save(Session session,Student transientInstance) {
		log.debug("saving Student instance");
		try {
			session.save(transientInstance);
			log.debug("save successful");
		}
		catch (RuntimeException re) {
			// TODO: handle exception
			log.error("save failed", re);
			throw re;
		}
	}
	
	public void delete(Session session, Student transientInstance) {
		log.debug("deleting Student instance");
		try {
			session.delete(transientInstance);
			log.debug("delete successful");
		}
		catch (RuntimeException re) {
			// TODO: handle exception
			log.error("delete failed", re);
			throw re;
		}
	}
	
	public void modify(String id, String name) {
		log.debug("modifing Student instance");
		try {
			Session session = getSession();
			Student student = session.get(Student.class, id);
			student.setName(name);
			
			session.update(student);
			log.debug("modify successful");
		}
		catch (RuntimeException re) {
			// TODO: handle exception
			log.error("modify failed", re);
			throw re;
		}
	}
	
		
}
